package com.d3works.apps.account.web;

import com.d3works.apps.account.db.PaymentMoveLineDistribution;
import com.d3works.apps.account.service.move.PaymentMoveLineDistributionService;
import com.d3works.exception.ResponseMessageType;
import com.d3works.exception.service.TraceBackService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;

@Singleton
public class PaymentMoveLineDistributionController {

  public void excludeLineFromDas2(ActionRequest request, ActionResponse response) {

    PaymentMoveLineDistribution paymentMoveLineD =
        request.getContext().asType(PaymentMoveLineDistribution.class);
    try {
      Beans.get(PaymentMoveLineDistributionService.class)
          .updateMoveInclusionInDas2Report(paymentMoveLineD.getMove(), true);
      response.setReload(true);
    } catch (Exception e) {
      TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
  }

  public void includeLineInDas2(ActionRequest request, ActionResponse response) {

    PaymentMoveLineDistribution paymentMoveLineD =
        request.getContext().asType(PaymentMoveLineDistribution.class);
    try {
      Beans.get(PaymentMoveLineDistributionService.class)
          .updateMoveInclusionInDas2Report(paymentMoveLineD.getMove(), false);
      response.setReload(true);
    } catch (Exception e) {
      TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
  }
}
